import { Component, OnInit } from '@angular/core';
import { LocalStorageService } from 'src/app/myService/local-storage.service';
import { Router } from '@angular/router';
import { SubscribeService } from 'src/app/myService/subscribe.service';
import { AxiosService } from '../../axios.service';


@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
  today: any = new Date();
  public date = new Date();
  public dateDay = this.date.getDay();
  public weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
  public week = this.weeks[this.dateDay];
  userInfo: any;
  name;
  name_PY;
  job_no;
  department;
  department_abb;
  role;
  password;
  level_choose = [];
  // remark; // 职位（主管审核...）


  constructor(
    private storage: LocalStorageService,
    private router: Router,
    public subscribe: SubscribeService,
    public axios: AxiosService,
  ) {
    //  this.subscribe.getLevel().subscribe((data) => {
    //   // console.log('pppppppppppppppp \n', data);
    //   if (data) {
    //     data=data.toString(2)
    //     // console.log('pppppppppppppppp \n', data);
    //     const dataStr = data + '';
    //     console.log('pppppppppppppppp \n', dataStr);
    //     const arrData = [];
    //     for( let i =0; i < dataStr.length; i++) {
    //       arrData.push(dataStr[i]);
    //     }
    //     this.level_choose = [];
    //     const list_length = 10; // 权限列表总长度

    //     // const levelchooseLength=this.level_choose.length;
    //     const arrdataLength=arrData.length; // level转化成二进制长度
    //     for (let i = list_length-1; i >=0; i--) {
    //       console.log('---------------------------------------\n', i);
    //       if (arrData.length -1 < i) {
    //         this.level_choose.push(false);
    //       } else {
    //         this.level_choose.push(true);
    //       }
    //     }
    //     console.log('123454 \n',this.level_choose)
    //   }
    // })

    const level_data = this.storage.getStorageData('user').level;
    if (level_data) {
      const data = level_data.toString(2)
      const dataStr = data + '';
      const arrData = [];
      for (let i = 0; i < dataStr.length; i++) {
        arrData.push(dataStr[i]);
      }

      for (let i = 0; i < arrData.length; i++) {
        if (arrData.length < 16) {
          arrData.unshift('0');
        }
      }
      for (let i = 0; i < arrData.length; i++) {
        // debugger
        if (arrData[i] === '0') {
          this.level_choose.push(false);
        } else {
          this.level_choose.push(true);
        }
      }

      // 查找符合item条件的下标
      // let index = this.level_choose.findIndex((item) => {
      //   return item === true
      // })
      // console.log(index)
      // let routerArr = ['audit', 'empDesign', 'empProgram', 'empProcess', 'empZhijian', 'empJiagong', 'empZuzhuang', 'empZongjian', 'ruku', 'paijian', 'empKufang', 'lingliao','kanbanManage','baobiao','paiban', 'permissions'];
      // console.log('home/' + routerArr[12])
      // this.router.navigate(['home/' + routerArr[index]]);
    }
  }

  ngOnInit(): void {
    //修改头部与左侧高度
    document.getElementsByClassName("ant-layout-header")[0].setAttribute('style', 'line-height:21px;padding:0 20px !important;');
    document.getElementsByClassName("ant-layout-sider-children")[0].setAttribute('style', 'height:0 !important;');
    this.userInfo = this.storage.getStorageData('user');
    console.log('--------------------\n', this.userInfo)
    this.name = this.userInfo.name;
    this.name_PY = this.userInfo.name_PY;
    this.job_no = this.userInfo.job_no;
    this.department = this.userInfo.department;
    this.department_abb = this.userInfo.department_abb;
    this.role = this.userInfo.role;
    this.password = this.userInfo.password;
    // this.remark = this.userInfo.remark;
  }

  cancel() {
    this.name = this.userInfo.job_no;
    const data = {};
    data['name'] = this.name;
    this.storage.removeAllStorageData();
    this.router.navigate(['/login', data]);
    this.axios.axiosPost('unLogin')
      .then((data) => {
        if (data) {
          console.log(data);
        }
      })
      .catch((err) => {
        console.log(err)
      })
  }

}
